package com.ruoyi.wechat.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.ruoyi.wechat.domain.Camp;
import com.ruoyi.wechat.domain.Message;
import com.ruoyi.wechat.domain.Project;
import com.ruoyi.wechat.mapper.CampMapper;
import com.ruoyi.wechat.mapper.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.ActivityMapper;
import com.ruoyi.wechat.domain.Activity;
import com.ruoyi.wechat.service.IActivityService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 营地活动Service业务层处理
 * 
 * @author jiang
 * @date 2024-11-25
 */
@Service
public class ActivityServiceImpl implements IActivityService 
{
    @Autowired
    private ActivityMapper activityMapper;
    @Resource
    private MessageMapper messageMapper;
    @Resource
    private CampMapper campMapper;

    /**
     * 查询营地活动
     * 
     * @param activityId 营地活动主键
     * @return 营地活动
     */
    @Override
    public Activity selectActivityByActivityId(String activityId)
    {
        return activityMapper.selectActivityByActivityId(activityId);
    }

    /**
     * 查询营地活动列表
     * 
     * @param activity 营地活动
     * @return 营地活动
     */
    @Override
    public List<Activity> selectActivityList(Activity activity)
    {
        return activityMapper.selectActivityList(activity);
    }

    /**
     * 新增营地活动
     * 
     * @param activity 营地活动
     * @return 结果
     */
    @Override
    public int insertActivity(Activity activity)
    {
        activity.setActivityId(UUID.randomUUID().toString());
        return activityMapper.insertActivity(activity);
    }

    /**
     * 修改营地活动
     * 
     * @param activity 营地活动
     * @return 结果
     */
    @Override
    public int updateActivity(Activity activity)
    {
        return activityMapper.updateActivity(activity);
    }

    /**
     * 批量删除营地活动
     * 
     * @param activityIds 需要删除的营地活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityByActivityIds(String[] activityIds)
    {
        return activityMapper.deleteActivityByActivityIds(activityIds);
    }

    /**
     * 删除营地活动信息
     * 
     * @param activityId 营地活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityByActivityId(String activityId)
    {
        return activityMapper.deleteActivityByActivityId(activityId);
    }

    /**
     * 活动审核
     *1.消息表新增数据
     *2.修改项目表的审核状态
     * @param message 审核消息
     * @return 结果
     */
    @Transactional
    @Override
    public int approveActivity(Message message) {
        //查询景点
        Activity activity = activityMapper.selectActivityByActivityId(message.getActivityId());
        //查询营地
        Camp camp = campMapper.selectCampByCampId(message.getCampId());
        //id
        message.setMessageId(UUID.randomUUID().toString());
        //审判时间
        message.setReleaseTime(new Date());
        //审核内容
        String content = message.getApprove().equals("1")?"审核通过，"+message.getContent():"审核失败，"+message.getContent();
        message.setContent("营地审核消息：“"+camp.getCampName()+"“营地的”"+activity.getActivityName()+"“活动"+content);
        message.setUserId(camp.getUserId());
        messageMapper.insertMessage(message);
        //修改景点表的审核状态
        activity.setApprove(message.getApprove());
        activityMapper.updateActivity(activity);
        return 1;
    }
}
